<?php
$this->headLink(array('href' => '/cms/styles/style.css', 'rel' => "stylesheet", 'type' => "text/css"));

$this->headStyle()->appendStyle(<<<EOD
#free {
	color: #00ff00;	
}
#occupied {
	color: #ff0000;
}
.hidden-box {
	display: none;
}
EOD
);

$this->headScript()
	->appendFile('/cms/scripts/dojo/dojo.js','',array('djConfig'=> 'parseOnLoad:true'))
	->setAllowArbitraryAttributes(true);
	
$this->headScript()
	->appendScript(<<<EOD

dojo.require("dojo.number");
	
dojo.addOnLoad(
	
	function () {
	
		dojo.query('#genPassBtn').connect('onclick',
			function () {
				dojo.xhrGet({
				    url: "/cms/users/genpass/new",
				    load: function(response, ioArgs) {
				        document.getElementById("password").value = response;
				        return false
				    },
				    error: function(response, ioArgs){
				        alert("An error occurred, with response: " + response);
				        return response;
				    },
				    handleAs: "text",
				    sync: true
				});
		});
		
		
		dojo.query('#login').connect('onkeyup',
			function (evt) {
				if (evt.target.value=='') { 
					dojo.query('#free').addClass('hidden-box');
					dojo.query('#occupied').addClass('hidden-box');
					dojo.byId('okButton').disabled = true;
				} else {
				
					dojo.xhrPost({
					    url: "/cms/users/checklogin",
					    content: {login: evt.target.value},
					    load: 
					    	function(response, ioArgs) {
						        if (response.substr(0,1)=='y') {
						        	dojo.query('#free').removeClass('hidden-box');
						        	dojo.query('#occupied').addClass('hidden-box');
						        	dojo.byId('okButton').disabled = false;
						        } else {
						        	dojo.query('#occupied').removeClass('hidden-box');
						        	dojo.query('#free').addClass('hidden-box');
						        	dojo.byId('okButton').disabled = true;
						        }
						        return false
						    },
					    error: function(response, ioArgs){
					        alert("An error occurred, with response: " + response);
					        return response;
					    },
					    handleAs: "text",
					    sync: false
					});
				}
			});
	}
);	
EOD
);
?>

<h1>Добавление пользователя</h1>
<form method="post" action="">
  <table border="0" cellpadding="0" cellspacing="0" class="form">
    <tr>
      <td class="lablel">Логин:</td>
      <td><input name="login" type="text" class="modalInput" id="login" /></td>
      <td class="stnd_font">
        <div id="free" class="hidden-box">Свободен</div>
        <div id="occupied" class="hidden-box">Занят</div>
      </td>
    </tr>
    <tr>
      <td class="lablel">Пароль:</td>
      <td><input name="password" type="text" class="modalInput" id="password" /></td>
      <td><input type="button" id="genPassBtn" class="modalInput" value="Сгенерировать" /></td>
    </tr>
    <tr>
      <td class="lablel">E-Mail:</td>
      <td><input name="email" type="text" class="modalInput" id="email" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td class="lablel">&nbsp;</td>
      <td colspan="2"><input type="checkbox" name="email_notify" id="email_notify" /> 
      Отправить пароль по почте</td>
    </tr>
    
    <tr>
      <td>&nbsp;</td>
      <td colspan="2"><input name="Submit" type="submit" class="okButton" id="okButton" value="Добавить" disabled="disabled" />
          <input type="button" class="okButton" value="Закрыть окно" onclick="window.parent.setTimeout('Shadowbox.close()',10)" /></td>
    </tr>
  </table>
</form>